﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Content Dialog item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SplitViewOptions
{
    public sealed partial class AddSitesContentDialog : ContentDialog
    {
        public AddSitesContentDialog()
        {
            this.InitializeComponent();
            if (string.IsNullOrEmpty(url.Text))
            {
                url.Text = App.Addurlstr;
            }
            if (string.IsNullOrEmpty(name.Text))
            {
                name.Text = App.Addnamestr;
            }
        }
       
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if(string.IsNullOrEmpty(name.Text))
            {
                await App.showmessage("不能为空");
                return;
            }
            if (string.IsNullOrEmpty(url.Text))
            {
                await App.showmessage("不能为空");
                return;
            }
            if(name.Text.Length>5)
            {
                await App.showmessage("不能超过5个字");
                return;
            }
            App.Addurlstr = url.Text;
            App.Addnamestr = name.Text;
            App.AddDesktopsites(App.Addurlstr, App.Addnamestr);
            this.Hide();
            url.Text = string.Empty;
            name.Text = string.Empty;
            App.Addurlstr = string.Empty;
            App.Addnamestr = string.Empty;
        await    App.Addoruodatedesktopsites();
        }

        private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
        }
    }
}
